In this study we will analyse economical Data of the Worldbank…
To simplify the Data we will aggregate it by regions as defined by the worldbank, please see the map below…
pal = tableau_color_pal(
palette = "Tableau 10")(10)
data("World")
World = World%>%
filter(continent!="Antarctica")
World$wb=countrycode(sourcevar = World$iso_a3,
origin = "iso3c",
destination = "region")
World = World%>%
filter(!is.na(wb))
ggplot(data = World) +
geom_sf(aes(fill=wb),color="white",size=.1)+
theme(legend.position = "none",x.axis.text="none")+
scale_fill_tableau()+
theme_igray()
# tmap_mode("plot")
#
# tm_shape(World) +
# tm_polygons("wb",palette=pal)
In this section there is an animated graph
Now we will have a look at selected Indicators
load("worldbankindicators.RData")
tmap_mode("view")
currentdata = worldbank_data%>%
filter(!is.na(Values))%>%
filter(year == 2020)%>%
mutate(iso_a3 =
countrycode(sourcevar = .$iso2c,
origin = "iso2c",
destination = "iso3c"))%>%
filter(!is.na(iso_a3))
vars = World%>%left_join(currentdata)
tm_shape(vars) +
tm_polygons("Values")+
tm_facets(by = "Indicator",free.scales=TRUE)
Now we will have a look at Inflation in further Detail.
#source("inflationdata.R")
load("inflationdata.RData")
data = data%>%
mutate(date=as.POSIXct(date))%>%
mutate(region = countrycode(sourcevar = data$region,
origin = "iso3n",
destination = "region")
)%>%
drop_na()%>%
group_by(region,`Series Name`,date)%>%
summarise(value=median(value,na.rm=T))%>%
drop_na()%>%
mutate(series = word(`Series Name`,1,-2))%>%
nest(data = -c(region,series))%>%
mutate(
test = map(data, ~ loess(.$value~as.numeric(.$date), span = .5)), # S3 list-col
tidied = map(test, augment,se.fit=T
)
)%>%
unnest(c(tidied,data))%>%
select(-test)%>%
data.frame()%>%
mutate(smooth = `.fitted`)%>%
mutate(ref=2)%>%
mutate(crisis=ifelse(
date > as.POSIXct(as.Date("2008-10-19 10:15")) & date < as.POSIXct(as.Date("2010-10-19 10:15")), 1, 0))
selection = alt$selection_single(fields=list("region"), bind='legend')
chart <-
alt$Chart()$
encode(
x=alt$X('date:T', axis=alt$Axis(title='Time')),
#x = "date:T",
#y = "smooth:Q",
strokeWidth=alt$value(2),
y=alt$Y('smooth:Q', axis=alt$Axis(title='Annual Inflation Rate')),
color="region:N",
tooltip=list('region:N','date:T'),
opacity=alt$condition(selection, alt$value(1), alt$value(0.2))
)$
mark_line()$
interactive()$
add_selection(
selection
)
rule = alt$Chart(
)$mark_rule(color='red')$encode(
y='ref:Q',
strokeWidth=alt$value(2)
)
all = alt$layer(chart,rule,data=data)$facet('series',columns=2,title="Yearly Inflation Rates by Month by Index and Worldbank-Regions")
all
m = data%>%
select(region,series,value,date)%>%
pivot_wider(id_cols=c(date,region),names_from=series,values_from=value)
korr = m%>%
select(-date)%>%
nest(data=-c(region))%>%
mutate(korr = map(data,cor),
tidied = map(korr, tidy))%>%
unnest(tidied)
rownames(korr$x)
## [1] "Energy Price" "Food Price"
## [3] "Headline Consumer Price" "Official Core Consumer Price"
## [5] "Energy Price" "Food Price"
## [7] "Headline Consumer Price" "Official Core Consumer Price"
## [9] "Energy Price" "Food Price"
## [11] "Headline Consumer Price" "Official Core Consumer Price"
## [13] "Energy Price" "Food Price"
## [15] "Headline Consumer Price" "Official Core Consumer Price"
## [17] "Energy Price" "Food Price"
## [19] "Headline Consumer Price" "Official Core Consumer Price"
## [21] "Energy Price" "Food Price"
## [23] "Headline Consumer Price" "Official Core Consumer Price"
## [25] "Energy Price" "Food Price"
## [27] "Headline Consumer Price" "Official Core Consumer Price"
t = data.frame(
series = rep(data$series%>%unique,data$region%>%unique%>%length),
region = korr$region,
corr = korr$x
)
colnames(t)[3:6]=data$series%>%unique
colnames(t)
## [1] "series" "region"
## [3] "Energy Price" "Food Price"
## [5] "Headline Consumer Price" "Official Core Consumer Price"
t_long=t%>%
pivot_longer(!c(series,region))
alt$Chart(t_long)$mark_rect()$encode(
x='series:N',
y='name:N',
color='value:Q',
tooltip = list("series:N","name:N","value:Q")
)$facet("region:N",columns=3)
m = data%>%
select(region,series,value,date)%>%
mutate(region2=region)%>%
mutate(region=series,series=region2)%>%
pivot_wider(id_cols=c(date,region),names_from=series,values_from=value)
korr = m%>%
select(-date)%>%
nest(data=-c(region))%>%
mutate(korr = map(data,cor),
tidied = map(korr, tidy))%>%
unnest(tidied)
rownames(korr$x)
## [1] "East Asia & Pacific" "Europe & Central Asia"
## [3] "Latin America & Caribbean" "Middle East & North Africa"
## [5] "North America" "South Asia"
## [7] "Sub-Saharan Africa" "East Asia & Pacific"
## [9] "Europe & Central Asia" "Latin America & Caribbean"
## [11] "Middle East & North Africa" "North America"
## [13] "South Asia" "Sub-Saharan Africa"
## [15] "East Asia & Pacific" "Europe & Central Asia"
## [17] "Latin America & Caribbean" "Middle East & North Africa"
## [19] "North America" "South Asia"
## [21] "Sub-Saharan Africa" "East Asia & Pacific"
## [23] "Europe & Central Asia" "Latin America & Caribbean"
## [25] "Middle East & North Africa" "North America"
## [27] "South Asia" "Sub-Saharan Africa"
d = data%>%
mutate(region2=region)%>%
mutate(region=series,series=region2)
t = data.frame(
series = rep(d$series%>%unique,d$region%>%unique%>%length),
region = korr$region,
corr = korr$x
)
colnames(t)[3:9]=d$series%>%unique
t_long=t%>%
pivot_longer(!c(series,region))
alt$Chart(t_long)$mark_rect()$encode(
x='series:N',
alt$Y('name:N', axis=alt$Axis(ticks=FALSE, domain=FALSE)),
color='value:Q',
tooltip = list("series:N","name:N","value:Q")
)$facet("region:N",columns=2)